import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
};
type ResultDelete = {
  code: number;
  msg: string;
};
type ResultCreate = {
  code: number;
  msg: string;
};
type Show = {
  code: number;
  msg: string;
  result?: any;
};

/** 订单列表 */
export const purchaseOrderListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/purchaseOrder/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 添加订单 */
export const purchaseOrderStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/purchaseOrder/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 编辑订单 */
export const purchaseOrderUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/purchaseOrder/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情订单 */
export const purchaseOrderShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/purchaseOrder/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除订单 */
export const purchaseOrderDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/purchaseOrder/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 选择订单 */
export const purchaseOrderSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/purchaseOrder/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 订单状态更新 */
export const purchaseOrderUpdateStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/purchaseOrder/updateStatus", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 订单撤销 */
export const purchaseOrderCancelApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/purchaseOrder/cancel", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

// 导出入库单
export const purchaseOrderExportApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/purchaseOrder/export", { data },{
    responseType: "blob"
  });
};
/***
*
*库存列表
*
*
*/
/** 库存列表 */
export const productListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/product/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情 */
export const productShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/product/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 流水列表 */
export const productFlowlogListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/productFlowlog/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 流水详情 */
export const productFlowlogShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/productFlowlog/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/***
*
*出库单列表
*
*
*/
/** 订单列表 */
export const deliveryOrderListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/deliveryOrder/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 添加订单 */
export const deliveryOrderStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/deliveryOrder/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 编辑订单 */
export const deliveryOrderUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/deliveryOrder/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情订单 */
export const deliveryOrderShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/deliveryOrder/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除订单 */
export const deliveryOrderDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/deliveryOrder/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 选择订单 */
export const deliveryOrderSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/deliveryOrder/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 订单状态更新 */
export const deliveryOrderUpdateStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/deliveryOrder/updateStatus", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

// 导出出库单
export const deliveryOrderExportApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/deliveryOrder/export", { data },{
    responseType: "blob"
  });
};
/***
*
*库存盘点API
*
*
*/
/** 订单列表 */
export const storeCheckListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/storeCheck/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 添加订单 */
export const storeCheckStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/storeCheck/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 编辑订单 */
export const storeCheckUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/storeCheck/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 订单状态更新 */
export const storeCheckUpdateStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/storeCheck/updateStatus", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};


/** 详情订单 */
export const storeCheckShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/storeCheck/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除订单 */
export const storeCheckDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/storeCheck/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 选择订单 */
export const storeCheckSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/storeCheck/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 选择仓库 */
export const storeListApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/store/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 入库信息模版 */
export const exportProCountLogForTodayPage = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/exportProCountLogForTodayPage", { params },{
    responseType: "blob"
  });
};

